//
//  ZCTopicPictureView.m
//  3期-百思不得姐
//
//  Created by xiaomage on 15/9/16.
//  Copyright (c) 2015年 xiaomage. All rights reserved.
//

#import "ZCTopicPictureView.h"
#import "ZCTopic.h"
#import <UIImageView+WebCache.h>
#import <AFNetworking.h>
@interface ZCTopicPictureView()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIImageView *gifView;
@property (weak, nonatomic) IBOutlet UIButton *seeBigPictureButton;

@end

@implementation ZCTopicPictureView 

- (void)awakeFromNib{
    [super awakeFromNib];
    //从xib中加载进来的控件的autoresizingMask默认是宽度和高度
    self.autoresizingMask = UIViewAutoresizingNone;
}

- (void)setTopic:(ZCTopic *)topic{
    //网络判断
//    AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
//    if (status == AFNetworkReachabilityStatusReachableViaWWAN) {//手机自带网络
//        [self.imageView sd_setImageWithURL:[NSURL URLWithString:topic.image0]];
//    }else if (status == AFNetworkReachabilityStatusReachableViaWiFi){//wifi
//        [self.imageView sd_setImageWithURL:[NSURL URLWithString:topic.image1]];
//    }else{//网络有问题，清空当前显示的图片
//        self.imageView.image = nil;
//    }
    self.gifView.hidden = !topic.is_gif;
    if (topic.is_bigPic) {
        self.seeBigPictureButton.hidden = NO;
        self.imageView.contentMode = UIViewContentModeTop;
        self.imageView.clipsToBounds = YES;
    }else{
        self.seeBigPictureButton.hidden = YES;
        self.imageView.contentMode = UIViewContentModeScaleToFill;
        self.imageView.clipsToBounds = NO;
    }
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:topic.image2]];
    //topic.image1.pathExtension.lowercaseString isEqualToString:@"gif"
//    topic.is_gif == YES
//    if ([topic.image1.lowercaseString hasSuffix:@"gif"]) {
//        self.gifView.hidden = NO;
//    }else{
//        self.gifView.hidden = YES;
//    }
    
    
}
@end
